package cn.inst.user.service;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import cn.inst.common.SecurityUntils;
import cn.inst.user.dao.UserMapper;
import cn.inst.user.domain.User;
import cn.inst.user.domain.UserExample;
@Service
public class CheckUserServiceImp implements CheckUserService {
	
	@Autowired
	private UserMapper uMapper;
	
	private UserExample uExample=new UserExample();
	@Override
	public User checkUser(User testUser) {
		String password = testUser.getPassword();
		uExample.clear();
		try {
			testUser.setPassword(SecurityUntils.MD5Password(password));
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		uExample.createCriteria().andUsernameEqualTo(testUser.getUsername()).andPasswordEqualTo(testUser.getPassword());
		List<User> list = uMapper.selectByExample(uExample);
		if(list.isEmpty()){
			return null;
		}else{
			return list.get(0);
		}
		
	}

}
